class Solution:
    def isPerfectSquare(self, num: int) -> bool:
        l, r = 0, num
        while l <= r:
            middle = (l + r)//2
            if middle * middle < num:
                l = middle + 1
            elif middle * middle > num:
                r = middle - 1
            else:
                return True
        return False